#ifndef __A235E8A7_AE85_408c_B150_098B41650451__
#define __A235E8A7_AE85_408c_B150_098B41650451__

#include <list>

namespace xos_stl
{

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // 
    // 

    template< class T, class ThreadLock >
	class auto_list
    {
    public:
        typedef std::list< T * >            T_LIST;
        typedef typename T_LIST::iterator   T_ITER;

    public:
        auto_list();
        ~auto_list();

    protected:
        ThreadLock m_lock;
        T_LIST m_list;

    public:
        void insert( T_ITER i_w, T_ITER first, T_ITER last );
        void insert( T * pT, T_ITER pBefore );
        void swap( auto_list & right );
        void put_back_to_pool();

        void unlock();
        void lock();

        T_ITER begin();
        T_ITER end();

        void pop_front();
        T * front();

        void push_front( T * pT );
        void push_back( T * pT );

        void erase( T_ITER iter );
        void remove( T * pT );
        void clear();

        size_t size();
        bool empty();
    };

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // method

    template< class T, class ThreadLock >
    auto_list< T, ThreadLock >::auto_list()
    {
    }

    template< class T, class ThreadLock >
    auto_list< T, ThreadLock >::~auto_list()
    {
        put_back_to_pool();
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::unlock()
    {
        m_lock.un_lock();
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::lock()
    {
        m_lock.lock();
    }

    template< class T, class ThreadLock >
    typename auto_list< T, ThreadLock >::T_ITER auto_list< T, ThreadLock >::begin()
    {
        return m_list.begin();
    }

    template< class T, class ThreadLock >
    typename auto_list< T, ThreadLock >::T_ITER auto_list< T, ThreadLock >::end()
    {
        return m_list.end();
    }

    template< class T, class ThreadLock >
    T * auto_list< T, ThreadLock >::front()
    {
        return m_list.front();
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::pop_front()
    {
        m_list.pop_front();
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::push_front( T * pT )
    {
        m_list.push_front( pT );
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::push_back( T * pT )
    {
        m_list.push_back( pT );
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::erase( typename auto_list< T, ThreadLock >::T_ITER iter )
    {
        m_list.erase( iter );
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::remove( T * pT )
    {
        m_list.remove( pT );
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::clear()
    {
        m_list.clear();
    }

    template< class T, class ThreadLock >
    bool auto_list< T, ThreadLock >::empty()
    {
        return m_list.empty();
    }

    template< class T, class ThreadLock >
    size_t auto_list< T, ThreadLock >::size()
    {
        return m_list.size();
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::swap( auto_list< T, ThreadLock > & right )
    {
        m_list.swap( right.m_list );
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::put_back_to_pool()
    {
        for( T_ITER iter = m_list.begin(); iter != m_list.end(); ++iter )
        {
            T * p = *iter;
            p->release();
            p = 0;
        }

        m_list.clear();
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::insert( typename auto_list< T, ThreadLock >::T_ITER i_w, \
        typename auto_list< T, ThreadLock >::T_ITER first, \
        typename auto_list< T, ThreadLock >::T_ITER last )
    {
        m_list.insert( i_w, first, last );
    }

    template< class T, class ThreadLock >
    void auto_list< T, ThreadLock >::insert( T * pT, typename auto_list< T, ThreadLock >::T_ITER iter )
    {
        m_list.insert( iter, pT );
    }


} // xos_stl

#endif // __A235E8A7_AE85_408c_B150_098B41650451__
